/*
 * @Description:
 * @Autor: lcz
 * @LastEditors: lcz
 * @LastEditTime: 2023-12-04 10:20:40
 */
import Cookies from "js-cookie";

const TokenKey = `${import.meta.env.VITE_APP_PROJECT_NAME_PREFIX}_Token`;

export function getToken() {
  return Cookies.get(TokenKey);
}

export function setToken(token: string) {
  return Cookies.set(TokenKey, token);
}

export function removeToken() {
  return Cookies.remove(TokenKey);
}

export function getCookie(key: string) {
  return Cookies.get(key);
}

export function setCookie(key: string, info: any) {
  return Cookies.set(key, info);
}

export function removeCookie(key: string) {
  return Cookies.remove(key);
}

/**
 * @description: Cookie类
 * @use get const cookieValue = CookieClass.get('cookieKey');
 * @use set CookieClass.set('cookieKey', 'cookieValue', { expires: 7 });
 * @use remove CookieClass.remove('cookieKey');
 * @author: lcz
 */
interface CookieOptions {
  expires?: number | Date;
  path?: string;
  domain?: string;
  secure?: boolean;
  sameSite?: "strict" | "lax" | "none";
}

export class CookieClass {
  // 避免时差
  static UTCString(days: number) {
    return new Date(new Date().getTime() + days * 24 * 60 * 60 * 1000);
  }
  // 获取Cookie
  static get(key: string): string | undefined {
    return Cookies.get(key);
  }

  // 设置Cookie
  static set(key: string, value: string, options?: CookieOptions): void {
    Cookies.set(key, value, options);
  }

  // 移除Cookie
  static remove(key: string, options?: CookieOptions): void {
    Cookies.remove(key, options);
  }
}
